package com.demo2do.boyle.common.entity.customer.wallet;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.boyle.common.entity.customer.Customer;

/**
 * 
 * @author Wilson leo
 * 
 */
@Entity
@Table(name = "withdrawal")
public class Withdrawal {

    @Id
    @GeneratedValue
    private Integer id;
    
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
	private Customer customer;

    private int balance;

    @Enumerated(EnumType.ORDINAL)
    private WithdrawalType type;

    private String account;
    
    private String accountName;

    @Enumerated(EnumType.ORDINAL)
    private WithdrawalStatus status;

    private Date createTime;
    
    private String auditor;

    @Column(name = "is_deleted")
    private boolean disabled;

    /**
     * default constructor
     */
    public Withdrawal() {
    	
    }
    
    /**
     * 
     * @param account
     * @param name
     * @param money
     * @param type
     */
    public Withdrawal(String account, String accountName, int balance, WithdrawalType type, Customer customer) {
    	this.account = account;
    	this.accountName = accountName;
    	this.balance = balance;
    	this.type = type;
    	this.customer = customer;
    }
    
    /**
     * 
     * @return
     */
    public Withdrawal initialize() {
        this.disabled = false;
        this.createTime = new Date();
        this.status = WithdrawalStatus.AUDITING;
        return this;
    }
    
    /**
	 * audit withdrawal and set status
	 * 
	 * @return
	 */
	public Withdrawal audit() {
		this.status = WithdrawalStatus.TRANSFERING;
		return this;
	}
    
	/**
	 * transfer withdrawal and set status
	 * 
	 * @return
	 */
	public Withdrawal transfer() {
		this.status = WithdrawalStatus.SUCCESS;
		return this;
	}
	
    /**
	 * 
	 * @param auditor
	 * @return
	 */
	public Withdrawal operator(String auditor) {
		this.auditor = auditor;
		return this;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @return the customer
	 */
	public Customer getCustomer() {
		return customer;
	}

	/**
	 * @return the balance
	 */
	public int getBalance() {
		return balance;
	}

	/**
	 * @return the type
	 */
	public WithdrawalType getType() {
		return type;
	}

	/**
	 * @return the account
	 */
	public String getAccount() {
		return account;
	}

	/**
	 * @return the accountName
	 */
	public String getaccountName() {
		return accountName;
	}

	/**
	 * @return the status
	 */
	public WithdrawalStatus getStatus() {
		return status;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @return the auditor
	 */
	public String getAuditor() {
		return auditor;
	}

	/**
	 * @return the disabled
	 */
	public boolean isDisabled() {
		return disabled;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param customer the customer to set
	 */
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * @param balance the balance to set
	 */
	public void setBalance(int balance) {
		this.balance = balance;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(WithdrawalType type) {
		this.type = type;
	}

	/**
	 * @param account the account to set
	 */
	public void setAccount(String account) {
		this.account = account;
	}

	/**
	 * @param accountName the accountName to set
	 */
	public void setaccountName(String accountName) {
		this.accountName = accountName;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(WithdrawalStatus status) {
		this.status = status;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @param auditor the auditor to set
	 */
	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	/**
	 * @param disabled the disabled to set
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
	
}
